﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Reflection;
using System.Resources;

namespace TeacherLeftHand.Util
{
    /// <summary>
    /// 
    /// </summary>
    public class ResxTranslationProvider : ITranslationProvider
    {
        public static string StartUpLang;

        #region Private Members

        private readonly ResourceManager _resourceManager;

        #endregion

        #region Construction

        /// <summary>
        /// Initializes a new instance of the <see cref="ResxTranslationProvider"/> class.
        /// </summary>
        /// <param name="baseName">Name of the base.</param>
        /// <param name="assembly">The assembly.</param>
        public ResxTranslationProvider(string baseName, Assembly assembly)
        {
            _resourceManager = new ResourceManager(baseName, assembly);
        }

        #endregion

        #region ITranslationProvider Members

        /// <summary>
        /// See <see cref="ITranslationProvider.Translate" />
        /// </summary>
        public object Translate(string key)
        {
            return _resourceManager.GetObject(key);
        }

        #endregion

        #region ITranslationProvider Members

        /// <summary>
        /// See <see cref="ITranslationProvider.AvailableLanguages" />
        /// </summary>
        public IEnumerable<CultureInfo> Languages
        {
            get
            {
                // TODO: Resolve the available languages
                if (StartUpLang != null) yield return new CultureInfo(StartUpLang);

                List<string> supportedLanguage = new List<string>();
                supportedLanguage.Add("en-US");
                supportedLanguage.Add("vi-VN");

                if (supportedLanguage.Contains(StartUpLang)) supportedLanguage.Remove(StartUpLang);
                supportedLanguage.Sort();
                foreach (string language in supportedLanguage)
                {
                    yield return new CultureInfo(language);
                }
            }
        }

        #endregion
    }
}
